﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Toybox.NicoSharp.Video.UnitTest
{
	[TestClass]
	public class Test_Video : AbstractTester
	{
		[TestMethod]
		public void Test_VideoContent()
		{
			//http://www.nicovideo.jp/watch/sm18707213
			string id = @"sm18707213";

			Video video = new Video(id);

			// ThumbInfo
			ThumbInfo tInfo = video.GetThumbInfo();
			Assert.IsNotNull(tInfo);

			// Flv
			Flv flv = video.GetFlv();
			Assert.IsNotNull(flv);
		}


		[TestMethod]
		public void Test_Flv_PostPacketV2006_user_owner()
		{
			//http://www.nicovideo.jp/watch/sm18707213	
			string id = @"sm18707213";

			Video video = new Video(id);

			// Flv
			Flv flv = video.GetFlv();

			PacketCreatorV2006 creator = new PacketCreatorV2006(flv);
			string postPacket = creator.ToString();

			Message.Packet packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);

			// 過去ログ
			// ここでは一気に取得しているがclick_revisonを正確にするなら
			// １スレッドずつ取得する
			creator.Thread = packet.thread[0];
			creator.When = DateTime.Parse("2013/03/01");

			postPacket = creator.ToString();
			packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);
		}

		[TestMethod]
		public void Test_Flv_PostPacketV2006_user_owner2()
		{
			//http://www.nicovideo.jp/watch/sm14702360
			string id = @"sm14702360";

			Video video = new Video(id);

			// Flv
			Flv flv = video.GetFlv();

			PacketCreatorV2006 creator = new PacketCreatorV2006(flv);
			string postPacket = creator.ToString();

			Message.Packet packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);

			// 過去ログ
			creator.Thread = packet.thread[0];
			creator.When = DateTime.Parse("2013/03/01");

			postPacket = creator.ToString();
			packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);
		}

		[TestMethod]
		public void Test_Flv_PostPacketV2006_user_com_owner()
		{
			//http://www.nicovideo.jp/watch/1310634995
			string id = @"1310634995";

			Video video = new Video(id);

			// Flv
			Flv flv = video.GetFlv();

			PacketCreatorV2006 creator = new PacketCreatorV2006(flv);
			string postPacket = creator.ToString();

			Message.Packet packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);

			// 過去ログ
			creator.Thread = packet.thread[0];
			creator.When = DateTime.Parse("2013/03/01");

			postPacket = creator.ToString();
			packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);
		}

		[TestMethod]
		public void Test_Flv_PostPacketV2006_user_script_owner()
		{
			//http://www.nicovideo.jp/watch/sm12165652
			string id = @"sm12165652";

			Video video = new Video(id);

			// Flv
			Flv flv = video.GetFlv();

			PacketCreatorV2006 creator = new PacketCreatorV2006(flv);
			string postPacket = creator.ToString();

			Message.Packet packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);

			// 過去ログ
			creator.Thread = packet.thread[0];
			creator.When = DateTime.Parse("2013/03/01");

			postPacket = creator.ToString();
			packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);
		}


		[TestMethod]
		public void Test_Flv_PostPacketV2009_user_owner()
		{
			//http://www.nicovideo.jp/watch/sm18707213	
			string id = @"sm18707213";

			Video video = new Video(id);

			// Flv
			Flv flv = video.GetFlv();

			PacketCreatorV2009 creator = new PacketCreatorV2009(flv);
			string postPacket = creator.ToString();

			Message.Packet packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);

			// 過去ログ
			// ここでは一気に取得しているがclick_revisonを正確にするなら
			// １スレッドずつ取得する
			creator.Thread = packet.thread[0];
			creator.When = DateTime.Parse("2013/03/01");

			postPacket = creator.ToString();
			packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);
		}

		[TestMethod]
		public void Test_Flv_PostPacketV2009_user_com_owner()
		{
			//http://www.nicovideo.jp/watch/1310634995
			string id = @"1310634995";

			Video video = new Video(id);

			// Flv
			Flv flv = video.GetFlv();

			PacketCreatorV2009 creator = new PacketCreatorV2009(flv);
			string postPacket = creator.ToString();

			Message.Packet packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);

			// 過去ログ
			creator.Thread = packet.thread[0];
			creator.When = DateTime.Parse("2013/03/01");

			postPacket = creator.ToString();
			packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);
		}

		[TestMethod]
		public void Test_Flv_PostPacketV2009_user_script_owner()
		{
			//http://www.nicovideo.jp/watch/sm12165652
			string id = @"sm12165652";

			Video video = new Video(id);

			// Flv
			Flv flv = video.GetFlv();

			PacketCreatorV2009 creator = new PacketCreatorV2009(flv);
			string postPacket = creator.ToString();

			Message.Packet packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);

			// 過去ログ
			creator.Thread = packet.thread[0];
			creator.When = DateTime.Parse("2013/03/01");

			postPacket = creator.ToString();
			packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);
		}


		[TestMethod]
		public void Test_Flv_PostChat()
		{
			//http://www.nicovideo.jp/watch/sm18707213	
			string id = @"sm18707213";

			Video video = new Video(id);

			// Flv
			Flv flv = video.GetFlv();

			PacketCreatorV2006 pCreator = new PacketCreatorV2006(flv);
			pCreator.ResFrom = 0;
			string postPacket = pCreator.ToString();

			Message.Packet packet = flv.PostPacket(postPacket);
			Assert.IsNotNull(packet);

			ChatCreator cCreator = new ChatCreator(flv, packet.thread[0]);
			cCreator.LastRes = packet.thread[0].last_res;
			cCreator.UpdateKey();
			cCreator.VPos = 0;
			cCreator.Mail = "184";
			cCreator.Content = "テスト2";

			string chat = cCreator.ToString();
			Message.ChatResult result = flv.PostChat(chat);
			Assert.IsNotNull(result);
		}

	}
}
